package com.gurun.model.database.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.gurun.model.database.entity.GateWayCommand;

import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.Single;

@Dao
public interface GateWayDao {

    @Query("SELECT * FROM gateway_command")
    public Single<List<GateWayCommand>> queryAllFlowable();

    @Query("SELECT * FROM gateway_command")
    public List<GateWayCommand> queryAll();

    @Query("SELECT * FROM gateway_command WHERE short_id = :short_id")
    public Single<List<GateWayCommand>> queryByShortId(int short_id);


    @Query("SELECT * FROM gateway_command WHERE sid = :sid")
    public Single<List<GateWayCommand>> queryBySid(String sid);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    public long insert(GateWayCommand gateWayCommand);

    @Delete
    public void delete(GateWayCommand gateWayCommand);

    @Query("DELETE FROM gateway_command")
    public void deleteAll();

    @Update
    public void update(GateWayCommand gateWayCommand);

    @Query("SELECT sid FROM gateway_command WHERE short_id = :short_id")
    public String querySidByShortId(int short_id);

    @Query("SELECT short_id FROM gateway_command WHERE sid = :sid")
    public int queryShortIdBySid(String sid);

    @Query("SELECT model FROM gateway_command WHERE short_id = :short_id")
    public String queryModelByShortId(int short_id);
}
